<template>
  <div>
    <Header_h />
    <div class="sq_box_content">
      <bannerInfo :info="info" />
    </div>
    <div class="new_box_bgcolor">
      <div class="new_box">
        <div class="container">
          <div class="s_flex s_align_items_start">
            <leftMenu :menu="menu" :check="active" @checkItem="checkItem" />
            <div style="width: 100%">
              <section class="core_content_left core_content">
                <div class="list_title" opentype="page">
                  <span class="sq_tilte3 sq_tilte_color" v-if="active == 0"
                    >全部</span
                  >
                  <span class="sq_tilte3 sq_tilte_color" v-if="active == 1"
                    >政策</span
                  >
                  <span class="sq_tilte3 sq_tilte_color" v-if="active == 2"
                    >法规</span
                  >
                </div>
                <div class="item_list">
                  <!-- <div class="item_list_img">
                  <div class="img_wap">
                    <img class="item_list_img" :src="news.tpic" alt="" />
                  </div>
                </div> -->
                  <div
                    v-for="(news, index) in newslistData.list"
                    :key="index"
                    @click="
                      $router.push({
                        path: '/web/policies/details',
                        query: { id: news.id },
                      })
                    "
                    class="
                      s_flex
                      s_align_items_center
                      s_justify_content_between
                      s_flex-wrap
                    "
                  >
                    <h3 class="sq_title3 line_h_30 sq_tilte_color">
                      {{ news.title }}
                    </h3>
                    <p class="sq_content sq_content_color">
                      {{ news.online_time }}
                    </p>
                  </div>
                </div>
              </section>
              <div class="pagination">
                <el-pagination
                  background
                  @size-change="handleSizeChange"
                  @current-change="handleCurrentChange"
                  :current-page="newslistData.page"
                  :page-size="newslistData.size"
                  layout="total, prev, pager, next, jumper"
                  :total="parseInt(newslistData.count)"
                  align="left"
                ></el-pagination>
              </div>
            </div>
          </div>
        </div>
      </div>
    </div>
    <Footer />
    <rightMenu @moveTo="moveTo" />
  </div>
</template>

<script>
import Header_h from "@/components/Header_h";
import Footer from "@/components/Footer";
import bannerInfo from "@/components/web/bannerInfo";
import leftMenu from "@/components/web/leftMenu";
import { policyList } from "@/api/web";
import rightMenu from "@/components/web/rightMenu";

export default {
  components: {
    Header_h,
    Footer,
    bannerInfo,
    leftMenu,
    rightMenu,
  },
  data() {
    return {
      newslistData: [],
      banner: [],
      info: {
        title: "政策资讯",
        content: "最新知识产权政策及新闻资讯",
        img: require("@/assets/web/banner1.png"),
      },
      check: -1,
      active: 0,
      menu: [
        {
          name: "全部",
        },
        {
          name: "政策",
        },
        {
          name: "法规",
        },
      ],
    };
  },
  mounted() {
    this.getList();
    this.getBanner();
  },
  methods: {
    moveTo() {
      window.scrollTo(0, 0);
    },
    async getBanner() {
      // try {
      //   this.banner = await bannerList({ from: 1 });
      // } catch (error) {
      //   this.$message.error(error.message);
      // }
    },
    async getList() {
      try {
        this.newslistData = await policyList({ type: this.active });
      } catch (error) {
        this.$message.error(error.message);
      }
    },
    //每页下拉显示数据
    async handleSizeChange(size) {
      try {
        this.newslistData = await policyList({
          page: currentPage,
          type: this.active,
        });
      } catch (e) {
        this.$message.error(e.message);
      }
    },
    //点击第几页
    async handleCurrentChange(currentPage) {
      try {
        this.newslistData = await policyList({
          page: currentPage,
          type: this.active,
        });
      } catch (e) {
        this.$message.error(e.message);
      }
    },
    goNews(id) {
      this.$router.push({ path: "/web/news/details", query: { id: id } });
    },
    webUrl(url) {
      window.open(url);
    },
    enter(index) {
      this.check = index;
    },
    leave() {
      this.check = -1;
    },
    checkItem(index) {
      this.active = index;
      this.getList();
    },
  },
};
</script>

<style lang="less" scoped>
/* core_content */
.new_box {
  margin-top: -4%;
  position: relative;
  z-index: 1;
  margin-bottom: 60px;
}
.core_content .item_list_img {
  width: 240px;
  object-fit: cover;
  overflow: hidden;
  .img_wap {
    padding-bottom: 56%;
    width: 100%;
    position: relative;
    img {
      width: 100%;
      transition: all 0.5s ease;
      &:hover {
        transform: scale(1.1);
      }
    }
  }
}

.li_active {
  width: 100%;
  background: #ffffff;
  box-shadow: 0 0 16px rgba(24, 76, 171, 0.16);
  border: none;
}

.right_info {
  width: 70%;
  // margin-left: 25px;
}

.core_content .item_list {
  padding: 0 30px;
  width: 100%;
  margin-bottom: 30px;
  background: #ffffff;
  cursor: pointer;
  transition: all 0.2s ease;
}

.core_content .item_list div {
  border-bottom: 1px solid var(--color9);
  padding: 20px 0;
}

.core_content .item_list div h3:hover {
  color: var(--color);
}

.core_content .item_list div:last-child {
  border-bottom: 0;
}

.core_content .item_list:last-child {
  margin-bottom: 0;
}

.content_spacing {
  margin: 10px auto;
}
.pagination {
  width: 90%;
  margin: 40px auto 0;
}
.core_content_left {
  width: 80%;
  margin-left: 250px;
  background-color: #fff;
  height: 100%;
  box-shadow: 3px 1px 21px 0px rgba(24, 76, 171, 0.26);
}
.core_content_right {
  width: 25%;
  background-color: #fff;
}
.content_right_spacing {
  margin: 10px 0;
}
.list_right {
  border-top: 1px solid #eee;
  padding: 10px 0;
  margin: 0 10px;
}
.right_title {
  margin: 0 10px;
  padding: 10px 0;
}

.list_title {
  height: 30px;
  border-bottom: 2px solid #f2f2f2;
  padding: 30px 0;
  margin: 0 30px;
  span {
    display: block;
    border-bottom: 2px solid var(--color);
    width: auto;
    height: 30px;
    float: left;
    padding: 0 5px;
    color: var(--color);
  }
}

/* core_content */

@media (max-width: 750px) {
  .core_content .item_list_img {
    width: 100%;
    height: 127px;
    margin-right: 0;
    margin-bottom: 20px;
  }
  .core_content_left {
    width: 100%;
    background-color: #fff;
    height: 100%;
  }
  .core_content {
    padding: 20px 0;
  }
  .core_content .item_list {
    padding: 0 15px;
    h3 {
      width: 100%;
    }
    p {
      margin-top: 10px;
    }
  }
  .list_title {
    margin: 0 15px;
  }
}
</style>

